{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fe927d60",
   "metadata": {},
   "source": [
    "----------------\n",
    "本学习记录人：戴祥哲\n",
    "学习时间：2021-11-4\n",
    "week-05\n",
    "[参考的文档](https://python.org/doc)\n",
    "[许老师博客](https://cnblogs.com/xuzhichao)\n",
    "\n",
    "----------------\n",
    "\n",
    "\n",
    "\n",
    "# 本周学习内容\n",
    "## 1.啤酒歌谣项目详解\n",
    "## 2.用户输入\n",
    "## 3.while循环\n",
    "## 4.列表的引入\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac05663a",
   "metadata": {},
   "source": [
    "# 1.啤酒歌谣项目详解（p43自己写，p44课本节解读）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "06695ad6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 百威s 在啤酒柜中\n",
      "99 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "98 百威s 在啤酒柜中\n",
      "\n",
      "98 百威s 在啤酒柜中\n",
      "98 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "97 百威s 在啤酒柜中\n",
      "\n",
      "97 百威s 在啤酒柜中\n",
      "97 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "96 百威s 在啤酒柜中\n",
      "\n",
      "96 百威s 在啤酒柜中\n",
      "96 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "95 百威s 在啤酒柜中\n",
      "\n",
      "95 百威s 在啤酒柜中\n",
      "95 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "94 百威s 在啤酒柜中\n",
      "\n",
      "94 百威s 在啤酒柜中\n",
      "94 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "93 百威s 在啤酒柜中\n",
      "\n",
      "93 百威s 在啤酒柜中\n",
      "93 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "92 百威s 在啤酒柜中\n",
      "\n",
      "92 百威s 在啤酒柜中\n",
      "92 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "91 百威s 在啤酒柜中\n",
      "\n",
      "91 百威s 在啤酒柜中\n",
      "91 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "90 百威s 在啤酒柜中\n",
      "\n",
      "90 百威s 在啤酒柜中\n",
      "90 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "89 百威s 在啤酒柜中\n",
      "\n",
      "89 百威s 在啤酒柜中\n",
      "89 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "88 百威s 在啤酒柜中\n",
      "\n",
      "88 百威s 在啤酒柜中\n",
      "88 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "87 百威s 在啤酒柜中\n",
      "\n",
      "87 百威s 在啤酒柜中\n",
      "87 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "86 百威s 在啤酒柜中\n",
      "\n",
      "86 百威s 在啤酒柜中\n",
      "86 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "85 百威s 在啤酒柜中\n",
      "\n",
      "85 百威s 在啤酒柜中\n",
      "85 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "84 百威s 在啤酒柜中\n",
      "\n",
      "84 百威s 在啤酒柜中\n",
      "84 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "83 百威s 在啤酒柜中\n",
      "\n",
      "83 百威s 在啤酒柜中\n",
      "83 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "82 百威s 在啤酒柜中\n",
      "\n",
      "82 百威s 在啤酒柜中\n",
      "82 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "81 百威s 在啤酒柜中\n",
      "\n",
      "81 百威s 在啤酒柜中\n",
      "81 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "80 百威s 在啤酒柜中\n",
      "\n",
      "80 百威s 在啤酒柜中\n",
      "80 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "79 百威s 在啤酒柜中\n",
      "\n",
      "79 百威s 在啤酒柜中\n",
      "79 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "78 百威s 在啤酒柜中\n",
      "\n",
      "78 百威s 在啤酒柜中\n",
      "78 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "77 百威s 在啤酒柜中\n",
      "\n",
      "77 百威s 在啤酒柜中\n",
      "77 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "76 百威s 在啤酒柜中\n",
      "\n",
      "76 百威s 在啤酒柜中\n",
      "76 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "75 百威s 在啤酒柜中\n",
      "\n",
      "75 百威s 在啤酒柜中\n",
      "75 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "74 百威s 在啤酒柜中\n",
      "\n",
      "74 百威s 在啤酒柜中\n",
      "74 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "73 百威s 在啤酒柜中\n",
      "\n",
      "73 百威s 在啤酒柜中\n",
      "73 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "72 百威s 在啤酒柜中\n",
      "\n",
      "72 百威s 在啤酒柜中\n",
      "72 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "71 百威s 在啤酒柜中\n",
      "\n",
      "71 百威s 在啤酒柜中\n",
      "71 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "70 百威s 在啤酒柜中\n",
      "\n",
      "70 百威s 在啤酒柜中\n",
      "70 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "69 百威s 在啤酒柜中\n",
      "\n",
      "69 百威s 在啤酒柜中\n",
      "69 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "68 百威s 在啤酒柜中\n",
      "\n",
      "68 百威s 在啤酒柜中\n",
      "68 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "67 百威s 在啤酒柜中\n",
      "\n",
      "67 百威s 在啤酒柜中\n",
      "67 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "66 百威s 在啤酒柜中\n",
      "\n",
      "66 百威s 在啤酒柜中\n",
      "66 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "65 百威s 在啤酒柜中\n",
      "\n",
      "65 百威s 在啤酒柜中\n",
      "65 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "64 百威s 在啤酒柜中\n",
      "\n",
      "64 百威s 在啤酒柜中\n",
      "64 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "63 百威s 在啤酒柜中\n",
      "\n",
      "63 百威s 在啤酒柜中\n",
      "63 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "62 百威s 在啤酒柜中\n",
      "\n",
      "62 百威s 在啤酒柜中\n",
      "62 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "61 百威s 在啤酒柜中\n",
      "\n",
      "61 百威s 在啤酒柜中\n",
      "61 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "60 百威s 在啤酒柜中\n",
      "\n",
      "60 百威s 在啤酒柜中\n",
      "60 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "59 百威s 在啤酒柜中\n",
      "\n",
      "59 百威s 在啤酒柜中\n",
      "59 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "58 百威s 在啤酒柜中\n",
      "\n",
      "58 百威s 在啤酒柜中\n",
      "58 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "57 百威s 在啤酒柜中\n",
      "\n",
      "57 百威s 在啤酒柜中\n",
      "57 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "56 百威s 在啤酒柜中\n",
      "\n",
      "56 百威s 在啤酒柜中\n",
      "56 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "55 百威s 在啤酒柜中\n",
      "\n",
      "55 百威s 在啤酒柜中\n",
      "55 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "54 百威s 在啤酒柜中\n",
      "\n",
      "54 百威s 在啤酒柜中\n",
      "54 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "53 百威s 在啤酒柜中\n",
      "\n",
      "53 百威s 在啤酒柜中\n",
      "53 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "52 百威s 在啤酒柜中\n",
      "\n",
      "52 百威s 在啤酒柜中\n",
      "52 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "51 百威s 在啤酒柜中\n",
      "\n",
      "51 百威s 在啤酒柜中\n",
      "51 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "50 百威s 在啤酒柜中\n",
      "\n",
      "50 百威s 在啤酒柜中\n",
      "50 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "49 百威s 在啤酒柜中\n",
      "\n",
      "49 百威s 在啤酒柜中\n",
      "49 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "48 百威s 在啤酒柜中\n",
      "\n",
      "48 百威s 在啤酒柜中\n",
      "48 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "47 百威s 在啤酒柜中\n",
      "\n",
      "47 百威s 在啤酒柜中\n",
      "47 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "46 百威s 在啤酒柜中\n",
      "\n",
      "46 百威s 在啤酒柜中\n",
      "46 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "45 百威s 在啤酒柜中\n",
      "\n",
      "45 百威s 在啤酒柜中\n",
      "45 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "44 百威s 在啤酒柜中\n",
      "\n",
      "44 百威s 在啤酒柜中\n",
      "44 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "43 百威s 在啤酒柜中\n",
      "\n",
      "43 百威s 在啤酒柜中\n",
      "43 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "42 百威s 在啤酒柜中\n",
      "\n",
      "42 百威s 在啤酒柜中\n",
      "42 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "41 百威s 在啤酒柜中\n",
      "\n",
      "41 百威s 在啤酒柜中\n",
      "41 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "40 百威s 在啤酒柜中\n",
      "\n",
      "40 百威s 在啤酒柜中\n",
      "40 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "39 百威s 在啤酒柜中\n",
      "\n",
      "39 百威s 在啤酒柜中\n",
      "39 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "38 百威s 在啤酒柜中\n",
      "\n",
      "38 百威s 在啤酒柜中\n",
      "38 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "37 百威s 在啤酒柜中\n",
      "\n",
      "37 百威s 在啤酒柜中\n",
      "37 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "36 百威s 在啤酒柜中\n",
      "\n",
      "36 百威s 在啤酒柜中\n",
      "36 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "35 百威s 在啤酒柜中\n",
      "\n",
      "35 百威s 在啤酒柜中\n",
      "35 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "34 百威s 在啤酒柜中\n",
      "\n",
      "34 百威s 在啤酒柜中\n",
      "34 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "33 百威s 在啤酒柜中\n",
      "\n",
      "33 百威s 在啤酒柜中\n",
      "33 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "32 百威s 在啤酒柜中\n",
      "\n",
      "32 百威s 在啤酒柜中\n",
      "32 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "31 百威s 在啤酒柜中\n",
      "\n",
      "31 百威s 在啤酒柜中\n",
      "31 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "30 百威s 在啤酒柜中\n",
      "\n",
      "30 百威s 在啤酒柜中\n",
      "30 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "29 百威s 在啤酒柜中\n",
      "\n",
      "29 百威s 在啤酒柜中\n",
      "29 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "28 百威s 在啤酒柜中\n",
      "\n",
      "28 百威s 在啤酒柜中\n",
      "28 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "27 百威s 在啤酒柜中\n",
      "\n",
      "27 百威s 在啤酒柜中\n",
      "27 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "26 百威s 在啤酒柜中\n",
      "\n",
      "26 百威s 在啤酒柜中\n",
      "26 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "25 百威s 在啤酒柜中\n",
      "\n",
      "25 百威s 在啤酒柜中\n",
      "25 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "24 百威s 在啤酒柜中\n",
      "\n",
      "24 百威s 在啤酒柜中\n",
      "24 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "23 百威s 在啤酒柜中\n",
      "\n",
      "23 百威s 在啤酒柜中\n",
      "23 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "22 百威s 在啤酒柜中\n",
      "\n",
      "22 百威s 在啤酒柜中\n",
      "22 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "21 百威s 在啤酒柜中\n",
      "\n",
      "21 百威s 在啤酒柜中\n",
      "21 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "20 百威s 在啤酒柜中\n",
      "\n",
      "20 百威s 在啤酒柜中\n",
      "20 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "19 百威s 在啤酒柜中\n",
      "\n",
      "19 百威s 在啤酒柜中\n",
      "19 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "18 百威s 在啤酒柜中\n",
      "\n",
      "18 百威s 在啤酒柜中\n",
      "18 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "17 百威s 在啤酒柜中\n",
      "\n",
      "17 百威s 在啤酒柜中\n",
      "17 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "16 百威s 在啤酒柜中\n",
      "\n",
      "16 百威s 在啤酒柜中\n",
      "16 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "15 百威s 在啤酒柜中\n",
      "\n",
      "15 百威s 在啤酒柜中\n",
      "15 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "14 百威s 在啤酒柜中\n",
      "\n",
      "14 百威s 在啤酒柜中\n",
      "14 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "13 百威s 在啤酒柜中\n",
      "\n",
      "13 百威s 在啤酒柜中\n",
      "13 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "12 百威s 在啤酒柜中\n",
      "\n",
      "12 百威s 在啤酒柜中\n",
      "12 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "11 百威s 在啤酒柜中\n",
      "\n",
      "11 百威s 在啤酒柜中\n",
      "11 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "10 百威s 在啤酒柜中\n",
      "\n",
      "10 百威s 在啤酒柜中\n",
      "10 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "9 百威s 在啤酒柜中\n",
      "\n",
      "9 百威s 在啤酒柜中\n",
      "9 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "8 百威s 在啤酒柜中\n",
      "\n",
      "8 百威s 在啤酒柜中\n",
      "8 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "7 百威s 在啤酒柜中\n",
      "\n",
      "7 百威s 在啤酒柜中\n",
      "7 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "6 百威s 在啤酒柜中\n",
      "\n",
      "6 百威s 在啤酒柜中\n",
      "6 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "5 百威s 在啤酒柜中\n",
      "\n",
      "5 百威s 在啤酒柜中\n",
      "5 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "4 百威s 在啤酒柜中\n",
      "\n",
      "4 百威s 在啤酒柜中\n",
      "4 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "3 百威s 在啤酒柜中\n",
      "\n",
      "3 百威s 在啤酒柜中\n",
      "3 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "2 百威s 在啤酒柜中\n",
      "\n",
      "2 百威s 在啤酒柜中\n",
      "2 (瓶) 百威s\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "1 百威 在啤酒柜中\n",
      "\n",
      "1 百威 在啤酒柜中\n",
      "1 (瓶) 百威\n",
      "一次可以拿一瓶\n",
      "pass it around\n",
      "没有啤酒可以拿走了，今日已经买完了\n",
      "\n"
     ]
    }
   ],
   "source": [
    "word = \"百威s\"\n",
    "# 循环，for 一般和range使用，range 决定了循环的次数\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,word,\"在啤酒柜中\")\n",
    "    print(beer_num,\"(瓶)\",word)\n",
    "    print(\"一次可以拿一瓶\")\n",
    "    print(\"pass it around\")\n",
    "    \n",
    "    if beer_num == 1:\n",
    "        print(\"没有啤酒可以拿走了，今日已经买完了\")\n",
    "    else:\n",
    "        new_num = beer_num-1\n",
    "        if new_num == 1:\n",
    "            word=\"百威\"\n",
    "        print(new_num,word,\"在啤酒柜中\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d757354b",
   "metadata": {},
   "source": [
    "# 2.用户输入（input）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97818f2a",
   "metadata": {},
   "source": [
    ">>1. input: 变量赋值---用户数据\n",
    ">>2. input的数据类型---str（字符串）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "03c1d9f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：起飞\n"
     ]
    }
   ],
   "source": [
    "# 1. input: 变量赋值---用户数据\n",
    "# 2. input的数据类型---str（字符串）\n",
    "\n",
    "username = input(\"请输入你的账号：\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "aebe8aaa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "起飞\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(type(username))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8d1212fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'起飞'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cacc69b5",
   "metadata": {},
   "source": [
    "##  2.1iput实践：用户登录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "36581465",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：4\n",
      "你输入的账号不存在或密码不正确，pick it\n"
     ]
    }
   ],
   "source": [
    "# 1.首先，数据库信息有账号和密码\n",
    "username_date =\"beibeibei\"\n",
    "password_date =\"10086\"\n",
    "\n",
    "\n",
    "# 2.用户登录：\n",
    " \n",
    "username = input(\"请输入你的账号：\")\n",
    "if username_date == username:\n",
    "    #账号存在，判断密码\n",
    "    password=input(\"请输入你的密码：\")\n",
    "    if password == password_date:\n",
    "        print(\"欢迎光临\")\n",
    "    # 账号正确，密码不正确\n",
    "    else:\n",
    "        print(\"你输入的账号不存在或密码不正确！重新再来\")\n",
    "else:\n",
    "    print(\"你输入的账号不存在或密码不正确，pick it\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "deff3628",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：1\n",
      "请输入你的密码：1\n",
      "你输入的账号不存在或密码不正确！pick it 你还有 2 次输入机会，否则5s后再来\n",
      "请输入你的账号：1\n",
      "请输入你的密码：1\n",
      "你输入的账号不存在或密码不正确！pick it 你还有 1 次输入机会，否则5s后再来\n",
      "请输入你的账号：1\n",
      "请输入你的密码：1\n",
      "5s后再来尝试\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-44-39cf47345bac>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m     \u001b[0musername\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你的账号：\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      8\u001b[0m     \u001b[0mpassword\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"请输入你的密码：\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m     \u001b[0mcount\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcount\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Program Files (x86)\\study\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m    858\u001b[0m                 \u001b[1;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    859\u001b[0m             )\n\u001b[1;32m--> 860\u001b[1;33m         return self._input_request(str(prompt),\n\u001b[0m\u001b[0;32m    861\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    862\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Program Files (x86)\\study\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m    902\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    903\u001b[0m                 \u001b[1;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 904\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Interrupted by user\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    905\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    906\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid Message:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "import time\n",
    "username_date =\"beibeibei\"\n",
    "password_date =\"10086\"\n",
    "count=5\n",
    "\n",
    "while True:\n",
    "    username = input(\"请输入你的账号：\")\n",
    "    password = input(\"请输入你的密码：\")\n",
    "    count=count-1\n",
    "\n",
    "    if username == username_date:\n",
    "        if password == password_date:\n",
    "            print(\"欢迎光临\")\n",
    "            #使用break结束循环\n",
    "            break\n",
    "        else:\n",
    "            if count==0:\n",
    "                print(\"5分钟后再来尝试\")\n",
    "                time.sleep(5)\n",
    "                count=5\n",
    "            else:   \n",
    "                #占位符：会改变的值（1.按照一定规律）\n",
    "                print(\"你输入的账号不存在或密码不正确！pick it 你还有\",count,\"次输入机会，否则5s后再来\")\n",
    "    else:\n",
    "        if count==0:\n",
    "            print(\"5s后再来尝试\")\n",
    "            time.sleep(5)\n",
    "            count=5\n",
    "        else:\n",
    "            print(\"你输入的账号不存在或密码不正确！pick it 你还有\",count,\"次输入机会，否则5s后再来\")\n",
    "\n",
    "       "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3979a3ba",
   "metadata": {},
   "source": [
    "## 2.2占位符和<font style=\"color:red\">字符串格式化</font>\n",
    "> 1. 请同学们实践 4、用户输入 [%s占位符打印用户信息](https://www.cnblogs.com/xuzhichao/p/11430272.html)\n",
    "> 2. 请同学们实践 4、用户输入 [.format()打印用户信息](https://www.cnblogs.com/xuzhichao/p/11430272.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7d4a48b",
   "metadata": {},
   "source": [
    "# while循环\n",
    "> 1. while True:无限循环\n",
    "> 2. break跳出循环：当符合某条件时，结束循环\n",
    "> 3. while True 也可以指定循环次数，只不过循环次数也是用条件来决定的，条件称：计数器 count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95e9a011",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "while True:\n",
    "    count = count + 1\n",
    "    print(\"你是傻逼！\",count)\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "334ab6b6",
   "metadata": {},
   "source": [
    "# 3.列表的引入\n",
    "> 1. [什么是列表](https://docs.python.org/3/tutorial/introduction.html#lists)\n",
    "> 2. 列表的形式：[value1,value2,...]\n",
    "> 3. 列表也是 [序列](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) 数据类型\n",
    ">> 1. 序列是有顺序的（即可以用索引 index 取值）\n",
    ">> 2. 序列可以 切片 ,切片完的结果仍是一个 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "1a7783a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "squares =[1,4,9,16,25]\n",
    "print(squares)\n",
    "print(type(squares))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "f1851dda",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'帅哥'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考：用户账号数据不止一个，那么想存储怎么办？\n",
    "username_datebase=\"帅哥，吴彦祖,起飞,彭于晏\"\n",
    "username_datebase[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "847f8f46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'帅哥'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_datebase_list = [\"帅哥\",\"吴彦祖\",\"起飞\",\"彭于晏\"]\n",
    "username_datebase_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c4350642",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'吴彦祖'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_datebase_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f43a77b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'起飞'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_datebase_list[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e035e8a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:彭于晏\n",
      "age:17\n",
      "job:护士\n",
      "salary:1311\n",
      "-------INFO OF 彭于晏 -------\n",
      "Name:彭于晏\n",
      "Age:17\n",
      "Job:护士\n",
      "Salary:1311\n",
      "\n"
     ]
    }
   ],
   "source": [
    "name = input(\"name:\")\n",
    "age = input(\"age:\")\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "info = '''-------INFO OF %s -------\n",
    "Name:%s\n",
    "Age:%s\n",
    "Job:%s\n",
    "Salary:%s\n",
    "'''% (name,name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4b004108",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------INFO OF 彭于晏 -------\n",
      "Name:彭于晏\n",
      "Age:17\n",
      "Job:护士\n",
      "Salary:1311\n",
      "\n"
     ]
    }
   ],
   "source": [
    "info2 =  '''-------INFO OF {_name} -------\n",
    "Name:{_name}\n",
    "Age:{_age}\n",
    "Job:{_job}\n",
    "Salary:{_salary}\n",
    "'''.format(_name=name,\n",
    "           _age=age,\n",
    "           _job=job,\n",
    "           _salary=salary)\n",
    "print(info2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff0d73c4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
